/*  static char SccsId[] = "@(#)agdfile.h	1.8   7/31/95";
 *
 *		Copyright (c) KUBOTA Corporation,
 *		1994, 1995 All Rights Reserved
 *
 *  This software comprises unpublished confidential information of 
 *  KUBOTA Corp. and may not be used, copied or made available to anyone,
 *  except in accordance with the license under which it is furnished.
 */

#ifndef _AGD_FILE_HEADER__
#define	_AGD_FILE_HEADER__

#if (defined(__osf__) && defined(__alpha))
#include	<values.h>
#else
#define MAXFLOAT      ((float)3.402e+38)
#endif

#include	"acfile.h"		/* Aurora Data file header */

/********************************************************************/

/* Table Type definitions <table_type> */
#define	AGD_TBLTYPE_GEOMTBL	0
#define	AGD_TBLTYPE_MODELTBL	1

/* Data Type definitions <data_type> */
#define AGD_SFT_FLOAT_VERTEX		0
#define AGD_SFT_FLOAT_VNORM		1
#define AGD_SFT_FLOAT_FNORM		2
#define AGD_SFT_FLOAT_UV		7

#define AGD_SFT_FIX_VERTEX		16
#define AGD_SFT_FIX_VNORM		17
#define AGD_SFT_FIX_FNORM		18
#define AGD_SFT_FIX_UV			23

#define AGD_SFT_UV_CONVERT		30

#define AGD_FLOAT_VERTEX	(1<<AGD_SFT_FLOAT_VERTEX)
#define AGD_FLOAT_VNORM		(1<<AGD_SFT_FLOAT_VNORM)
#define AGD_FLOAT_FNORM		(1<<AGD_SFT_FLOAT_FNORM)
#define AGD_FLOAT_UV		(1<<AGD_SFT_FLOAT_UV)

#define AGD_FLOAT_ALL		( AGD_FLOAT_VERTEX | \
					AGD_FLOAT_VNORM | \
					AGD_FLOAT_FNORM |\
					AGD_FLOAT_UV )

#define AGD_FIX_VERTEX		(1<<AGD_SFT_FIX_VERTEX)
#define AGD_FIX_VNORM		(1<<AGD_SFT_FIX_VNORM)
#define AGD_FIX_FNORM		(1<<AGD_SFT_FIX_FNORM)
#define AGD_FIX_UV		(1<<AGD_SFT_FIX_UV)

#define AGD_FIX_ALL		( AGD_FIX_VERTEX |\
				        AGD_FIX_VNORM | \
					AGD_FIX_FNORM | \
					AGD_FIX_UV )

#define AGD_UV_CONVERT		(1 << AGD_SFT_UV_CONVERT)

/**********************************************************
#define AGD_FIX_FORMAT_VERTEX		FIXTYPE(1, 0, 15)
#define AGD_FIX_FORMAT_VNORM		FIXTYPE(1, 0, 15)
#define AGD_FIX_FORMAT_FNORM		FIXTYPE(1, 0, 15)
#define AGD_FIX_FORMAT_ECOLOR		FIXTYPE(0, 12, 0)
#define AGD_FIX_FORMAT_GCOLOR		FIXTYPE(0, 12, 0)
#define AGD_FIX_FORMAT_VTEXI		FIXTYPE(0, 8, 0)
#define AGD_FIX_FORMAT_OBJECT_MATRIX	FIXTYPE(1, 8, 7)
#define AGD_FIX_FORMAT_NORMAL_MATRIX	FIXTYPE(1, 0, 15)
#define AGD_FIX_FORMAT_LIGHT		FIXTYPE(1, 0, 15)
#define AGD_FIX_FORMAT_AMBIENT		FIXTYPE(0, 0, 15)
#define AGD_FIX_FORMAT_DIFFUSE		FIXTYPE(0, 0, 15)
#define AGD_FIX_FORMAT_SPECULAR		FIXTYPE(0, 0, 15)
#define AGD_FIX_FORMAT_EYEVECT		FIXTYPE(1, 0, 15)
**********************************************************/

/* Geometry Type definitions <geometry_type> */
#define	AGD_GEOM_TRISTRIP	1
#define	AGD_GEOM_TRILIST	2
#define	AGD_GEOM_POLYLINE	3
#define	AGD_GEOM_LINELIST	4
#define	AGD_GEOM_PNTLIST	5

/* Bounding box definitions <bbox> */
#define AGD_MAX_X		0
#define AGD_MAX_Y		1
#define AGD_MAX_Z		2
#define AGD_MIN_X		3
#define AGD_MIN_Y		4
#define AGD_MIN_Z		5
#define AGD_MAX_FLOAT_PLUS	MAXFLOAT
#define AGD_MAX_FLOAT_MINUS	(-MAXFLOAT)

#ifndef max
#define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
#endif
#ifndef min
#define min(a,b)  ( ((a) < (b)) ? (a) : (b) )
#endif

/*******************
  for file image
 *******************/

/********************************************************************/
/* define type of file image structure */

typedef struct { /* 16 bytes */
/* Aurora tools characteristic structure member <16 bytes> */
	CARD16	display_mode;		/* 48..49 */
	CARD16	colormap_type;		/* 50..51 */
	CARD16	colormap_id;		/* 52..53 */
	CARD16	modeltbl_cnt;		/* 54..55 */
	CARD32	modeltbl_addr;		/* 56..59 */
	CARD32	modeltbl_size;		/* 60..63 */
} fmodelhdr_t;

typedef struct { /* 64 bytes */
	CARD8	table_type;		/*  0..0  */
	CARD8	model_id;		/*  1..1  */
	CARD16	ngeometries;		/*  2..3  */
	CARD8	modelname[16];		/*  4..19 */
	CARDF32	scale[3];		/* 20..31 */
	CARDF32	bbox[6];
	CARD32	geomtbl_addr;		/* 32..35 */
	CARD32	geomtbl_size;		/* 36..39 */
} fmodeltbl_t;

typedef struct { /* 64 bytes */
	CARD8	geometry_type;		/*  0..0  */
	CARD8	geometry_id;		/*  1..1  */
	CARD8	texture_tag;		/*  2..2  */
	CARD8	reserved1;		/*  3..3  */
	CARDF32	bbox[6];		/*  4..27 */
	CARD32	data_type;		/* 28..31 */
	CARD32	nelements;		/* 32..35 */
	CARD32	vertices;		/* 36..39 */
	CARD32	vnormals;		/* 40..43 */
	CARD32	fnormals;		/* 44..47 */
	CARD32	vcolor;			/* 48..51 */
	CARD32	fcolor;			/* 52..55 */
	CARD32	gcolor;			/* 56..59 */
	CARD32	vtexi;			/* 60..63 */
} fgeomtbl_t;

/********************************************************************/

/* define type of memory image structure */

typedef struct { 
/* Aurora tools characteristic structure member */
	CARD16	display_mode;
	CARD16	colormap_type;
	CARD16	colormap_id;
	CARD16	modeltbl_cnt;
	void 	*modeltbl_addr;
	CARD32	modeltbl_size;
} modelhdr_t;

typedef struct {
	CARD8	table_type;
	CARD8	model_id;
	CARD16	ngeometries;
	CARD8	modelname[16];
	CARDF32	scale[3];
	CARDF32	bbox[6];
	void	*geomtbl_addr;
	CARD32	geomtbl_size;
} modeltbl_t;

typedef struct { 
	CARD8	geometry_type;
	CARD8	geometry_id;
	CARD8	texture_tag;
	CARD8	reserved1;
	CARDF32	bbox[6];
	CARD32	data_type;
	CARD32	nelements;
	void	*vertices;
	void	*vnormals;
	void	*fnormals;
	void	*vcolor;
	void	*fcolor;
	void	*gcolor;
	void	*vtexi;	
} geomtbl_t;

#endif	/* _AGD_FILE_HEADER__ */

